<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('用况详情')" />
	<link th:href="@{/css/common.css}" rel="stylesheet"/>
	<link th:href="@{/css/detail.css}" rel="stylesheet"/>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
	<div class="content">
		<input th:field="*{usage.id}" id="id" type="hidden">
		<div class="content-box">
			<div class="info-head">
				<p class="pull-left">
					<span th:text="${usage.usageyName}"></span>
				</p>
			</div>
			<div class="tips" th:text="${usage.usageyDescription}"></div>
			<div class="table-info">
				<ul class="list-group">
					<li class="list-group-item">
						<span>用况类型</span>
						<span th:text="${usage.usageType=='1'?'增': (usage.usageType=='2' ? '删' : (usage.usageType=='3' ? '改' : '查'))}"></span>
					</li>
					<li class="list-group-item">
						<span>是否单模块</span>
						<span th:text="${usage.isAlone=='Y'?'是':'否'}"></span>
					</li>
					<li class="list-group-item">
						<span>前后台类型</span>
						<span th:text="${usage.fbType=='1'?'前台':'后台'}"></span>
					</li>
					<li class="list-group-item">
						<span>用况故事</span>
						<span th:text="${usage.usageStory}"></span>
					</li>
					<li class="list-group-item"></li>
					<li class="list-group-item"></li>
					<li class="list-group-item">
						<span>价值描述</span>
						<span th:text="${usage.valueDescription}"></span>
					</li>
					<li class="list-group-item"></li>
					<li class="list-group-item"></li>
					<li class="list-group-item">
						<span>业务实现逻辑描述</span>
						<span th:text="${usage.businessImplDescription}"></span>
					</li>
					<li class="list-group-item"></li>
					<li class="list-group-item"></li>
					<li class="list-group-item">
						<span>终端类型</span>
						<span th:text="${usage.clientType=='1'?'PCweb': (usage.clientType=='2' ? 'H5' : (usage.clientType=='3' ? 'APP' : '微信小程序'))}">一</span>
					</li>
					<li class="list-group-item">
						<span>版本类型</span>
						<span th:text="${usage.versionType=='1'?'新功能': (usage.versionType=='2' ? '优化' : '废弃')}"></span>
					</li>
					<li class="list-group-item">
						<span>废弃说明</span>
						<span th:text="${usage.versionDescription}">一</span>
					</li>
					<li class="list-group-item">
						<span>分类名称</span>
						<span th:text="${usage.categoryName}"></span>
					</li>
					<li class="list-group-item">
						<span>参与角色</span>
						<span th:text="${roleNames}"></span>
					</li>
					<li class="list-group-item">
						<span>创建人</span>
						<span th:text="${usage.createBy}">王树立</span>
					</li>
					<li class="list-group-item">
						<span>创建时间</span>
						<span th:text="${#dates.format(usage.createTime, 'yyyy-MM-dd HH:mm:ss')}">2021.11.21 13:21</span>
					</li>
					<li class="list-group-item"></li>
					<li class="list-group-item">
						<span>更新人</span>
						<span th:text="${usage.updateBy}">王树立</span>
					</li>
					<li class="list-group-item">
						<span>更新时间</span>
						<span th:text="${#dates.format(usage.updateTime, 'yyyy-MM-dd HH:mm:ss')}">2021.11.21 13:21</span>
					</li>
				</ul>
			</div>
			<ul class="nav nav-tabs navtabs contentTab" role="tablist">
				<li class="active"><a href="#content-business" role="tab" data-action = "relationBusinessList" data-toggle="tab">关联业务需求</a></li>
				<li><a href="#content-bff" role="tab" data-toggle="tab" data-action = "relationBff">关联BFF接口</a></li>
				<li><a href="#content-page" role="tab" data-toggle="tab" data-action = "relationPageList">关联页面</a></li>
				<li><a href="#content-service" role="tab" data-toggle="tab" data-action = "relationBusinessSystemList">关联业务系统</a></li>
			</ul>
			<div class="tab-content">
				<div role="tabpanel" class="tab-pane active mt20 " id="content-business"></div>
				<div role="tabpanel" class="tab-pane mt20 content-field" id="content-bff">

				</div>
				<div role="tabpanel" class="tab-pane mt20 content-page" id="content-page"></div>
				<div role="tabpanel" class="tab-pane mt20 content-service" id="content-service"></div>
			</div>
		</div>
	</div>
</div>
</div>
</div>
</body>
<th:block th:include="include :: footer"/>

<!--关联业务需求-->
<script id="contentBusinessTpl" type="text/template">
	<table class="table">
		<thead>
		<tr>
			<th>业务名称</th>
			<th>业务说明</th>
			<th>是否是问题</th>
			<th>需求类型</th>
			<th>紧急程度</th>
			<th>重要程度</th>
			<th>实现必要性</th>
			<th>实现客户必要性</th>
			<th>实现公司必要性</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody>
		{{# layui.each(d.businessList, function(index, a){ }}
		<tr>
			<td>{{a.businessName || '一'}}</td>
			<td>{{a.businessDescription || '一'}}</td>
			<td>{{# if(a.isQuestion=='N'){ }}否{{# } else {}}是{{#} }}</td>
			<td>{{# if(a.businessType=='1') { }} 普通 {{# } else if(a.businessType == '2') { }} 痒点 {{# } else if(a.businessType == '3') { }} 爽点 {{#} else { }}痛点{{#}}}</td>
			<td>{{# if(a.degree=='1') { }} 一般 {{# } else if(a.degree == '2') { }} 中等 {{#} else { }}紧急{{#}}}</td>
			<td>{{# if(a.important=='1') { }} 一般 {{# } else if(a.important == '2') { }} 中等 {{#} else { }}紧急{{#}}}</td>

			<td>{{a.implementationNecessity || '一'}}</td>
			<td>{{a.implementationCustomerNecessity || '一'}}</td>
			<td>{{a.implementationCampanyNecessity || '一'}}</td>
			<td><a href="#" onclick="businessDetail({{a.id}})">查看详情</a></td>
		</tr>
		{{# }); }}
		</tbody>
	</table>
</script>

<script id="virtualUsageTpl" type="text/template">
	{{# layui.each(d.list, function(index, a){ }}
	<div class="panel panel-default virtualUsage">
		<div class="panel-heading" data-toggle="collapse" data-parent="#accordion" href="#collapse{{a.sortNum}}" data-id="{{a.id}}">
			<h1 class="panel-title">
				<span class="badge badge-primary">{{index+1}}</span>
				<span>{{a.slaveInterfaceName}}&nbsp;&nbsp;{{a.dubboUrl}}</span>
			</h1>
		</div>
		<div id="collapse{{a.sortNum}}" class="panel-collapse collapse"></div>
	</div>
	{{# }); }}
</script>
<!--关联字段模板-->
<script id="contentFieldTpl" type="text/template">
	<ul class="nav nav-tabs" role="tablist">
		<li class="active"><a href="#params-in" role="tab" data-toggle="tab">入参({{d.inFieldCount}})</a></li>
		<li><a href="#params-out" role="tab" data-toggle="tab">出参({{d.outFieldCount}})</a></li>
	</ul>
	<div class="tab-content">
		<div role="tabpanel" class="tab-pane active" id="params-in">
			<table class="table">
				<thead>
				<tr>
					<th>编号</th>
					<th>中文名称</th>
					<th>字段名称</th>
					<th>类型</th>
					<th>外键类型</th>
					<th>是否枚举字段</th>
					<th>是否状态字段</th>
					<th>数据类型</th>
					<th>字符数</th>
					<th>模拟数据</th>
					<th>模拟数据明细举例</th>
					<th>字段需求故事</th>
				</tr>
				</thead>
				<tbody>
				{{# layui.each(d.inFieldList, function(index, a){ }}
				<tr>
					<td>{{a.id || '一'}}</td>
					<td>{{a.fieldName || '一'}}</td>
					<td>{{a.fieldEnName || '一'}}</td>
					<td>{{# if(a.fieldType=='1') { }} 主键 {{# } else if(a.fieldType == '2') { }} 外键 {{#} else { }}属性{{#}}}</td>
					<td>{{# if(a.fkFieldType=='1'){ }}核心模型关系{{# } else {}}冗余模型关系{{#} }}</td>
					<td>一</td>
					<td>{{# if(a.isFieldStatus=='N'){ }}否{{# } else {}}是{{#} }}</td>
					<td>{{# if(a.fieldDataType=='1') { }} 文本 {{# } else if(a.fieldDataType == '2') { }} 数字 {{#} else { }}时间{{#}}}</td>
					<td>一</td>
					<td>{{a.mockData || '一'}}</td>
					<td>{{a.mockDescription || '一'}}</td>
					<td>{{a.fieldStory || '一'}}</td>
				</tr>
				{{# }); }}
				</tbody>
			</table>
		</div>
		<div role="tabpanel" class="tab-pane" id="params-out">
			<table class="table">
				<thead>
				<tr>
					<th>编号</th>
					<th>中文名称</th>
					<th>字段名称</th>
					<th>类型</th>
					<th>外键类型</th>
					<th>是否枚举字段</th>
					<th>是否状态字段</th>
					<th>数据类型</th>
					<th>字符数</th>
					<th>模拟数据</th>
					<th>模拟数据明细举例</th>
					<th>字段需求故事</th>
				</tr>
				</thead>
				<tbody>
				{{# layui.each(d.outFieldList, function(index, a){ }}
				<tr>
					<td>{{a.id || '一'}}</td>
					<td>{{a.fieldName || '一'}}</td>
					<td>{{a.fieldEnName || '一'}}</td>
					<td>{{# if(a.fieldType=='1') { }} 主键 {{# } else if(a.fieldType == '2') { }} 外键 {{#} else { }}属性{{#}}}</td>
					<td>{{# if(a.fkFieldType=='1'){ }}核心模型关系{{# } else {}}冗余模型关系{{#} }}</td>
					<td>一</td>
					<td>{{# if(a.isFieldStatus=='N'){ }}否{{# } else {}}是{{#} }}</td>
					<td>{{# if(a.fieldDataType=='1') { }} 文本 {{# } else if(a.fieldDataType == '2') { }} 数字 {{#} else { }}时间{{#}}}</td>
					<td>一</td>
					<td>{{a.mockData || '一'}}</td>
					<td>{{a.mockDescription || '一'}}</td>
					<td>{{a.fieldStory || '一'}}</td>
				</tr>
				{{# }); }}
				</tbody>
			</table>
		</div>
	</div>
</script>

<script id="contentBffTpl" type="text/template">
	<div class="info-head">
		<p class="pull-left">
			<span class="label label-flag">{{# if(d.interfaceType=='1') { }} GET {{# } else if(d.interfaceType == '2') { }} POST {{# } else if(d.optType == '3') { }} PUT {{#} else { }}DELETE{{#}}}</span>
			<span>{{d.interfaceName}}</span>
			<span>{{d.interfaceUrl}}</span>
		</p>
		<p class="pull-right">
			<a onclick="bffDetail({{d.id}})">查看详情</a>
		</p>
	</div>
	<div class="tips">{{d.interfaceDescription}}</div>
	<div class="table-info">
		<ul class="list-group">
			<li class="list-group-item">
				<span>读写类型</span>
				<span>{{# if(d.optType=='1') { }} 增 {{# } else if(d.optType == '2') { }} 删 {{# } else if(d.optType == '3') { }} 改 {{#} else { }}查{{#}}}</span>
			</li>
			<li class="list-group-item">
				<span>前后类型</span>
				<span>BFF</span>
			</li>
			<li class="list-group-item">
				<span>是否分页</span>
				<span>{{# if(d.isPage=='N'){ }}否{{# } else {}}是{{#} }}</span>
			</li>
			<li class="list-group-item">
				<span>内容条数</span>
				<span>{{d.total || '--'}}</span>
			</li>
			<li class="list-group-item">
				<span>页数</span>
				<span>{{d.page || '--'}}</span>
			</li>
			<li class="list-group-item">
				<span>分页内容数</span>
				<span>{{d.pageSize || '--'}}</span>
			</li>
		</ul>
	</div>
</script>

<!--关联字段模板-->
<script id="contentTableTpl" type="text/template">
	{{# layui.each(d, function(index, a){ }}
		<div class="retation-table">
			<p class="blue-background">
				<img th:src="@{/img/table.png}">
				<span>{{a.tableName}}&nbsp;&nbsp;{{a.tableEnName}}</span>
				<span  style="color: #0088FF;float: right;margin-right: 12px;"><a class = "table-detail" tableId = "{{a.id}}">查看详情</a></span>
			</p>
			<ul class="list-group">
				{{# layui.each(a.fieldInfoList, function(indexB, b){ }}
					{{# if(b.categorySpace) { }}
						<li class="list-group-item space"></li>
					{{# }}}
					<li class="list-group-item">
						<font>{{# if(b.fieldType=='1') { }} PK {{# } else if(b.fieldType == '2') { }} FK {{#} else { }}-{{#}}}</font>
						<span title="{{b.fieldName || '一'}}">{{b.fieldName || '一'}}</span>
						<span>
							{{b.fieldEnName || '一'}}
							{{# if(b.fieldLength) { }}
								({{b.fieldLength}})
							{{# } }}
						</span>
						<span>{{# if(b.fieldDataType=='1') { }} 文本 {{# } else if(b.fieldDataType == '2') { }} 数字 {{#} else { }}日期{{#}}}</span>
					</li>
				{{# }); }}
			</ul>
		</div>
	{{# }); }}
</script>

<!--关联页面模板-->
<script id="contentPageTpl" type="text/template">
	<table class="table">
		<thead>
		<tr>
			<th>页面名称</th>
			<th>页面描述</th>
			<th>是否模块聚合页</th>
			<th>是否风险点</th>
			<th>终端类型</th>
			<th>分类名称</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody>
		{{# layui.each(d, function(index, a){ }}
		<tr>
			<td>{{a.pageName || '一'}}</td>
			<td>{{a.pageDescription || '一'}}</td>
			<td>{{# if(a.isModuleAggregation=='N'){ }}否{{# } else {}}是{{#} }}</td>
			<td>{{# if(a.isRask=='N'){ }}否{{# } else {}}是{{#} }}</td>
			<td>{{# if(a.terminalType=='1') { }} PCweb {{# } else if(a.terminalType == '2') { }} H5 {{# } else if(a.terminalType == '3') { }} APP {{#} else { }}微信小程序{{#}}}</td>
			<td>{{a.categoryName || '一'}}</td>
			<td><a href="#" onclick="pageDetail({{a.id}})">查看详情</a></td>
		</tr>
		{{# }); }}
		</tbody>
	</table>
</script>

<!--关联用况模板-->
<script id="contentUsageTpl" type="text/template">
	<ul class="list-group">
		{{# layui.each(d, function(index, a){ }}
			<li class="list-group-item">
				<div class="list-tit">
					<p>
						<span>{{# if(a.fbType=='1') { }} 前台 {{#} else { }}后台{{#}}}</span>
						<span>{{# if(a.usageType=='1') { }} 增 {{# } else if(a.usageType == '2') { }} 删 {{# } else if(a.usageType == '3') { }} 改 {{#} else { }}查{{#}}}</span>
						<span>{{a.usageyName || '一'}}</span>
					</p>
					<p>
						<span>用况架构</span>
						<span>
							{{# if(a.clientType=='1') { }} PCweb {{# } else if(a.clientType == '2') { }} H5 {{# } else if(a.clientType == '3') { }} APP {{#} else { }} 微信小程序 {{#}}}
							· {{# if(a.isAlone=='1') { }} 单模块 {{#} else { }} 非单模块 {{# }}}
							· {{# if(a.versionType=='1') { }} 新功能 {{# } else if(a.versionType == '2') { }} 优化 {{#} else { }} 废弃 {{#}}}
						</span>
					</p>
				</div>
				<div class="list-content">
					<p>用况故事</p>
					<p>{{a.usageStory || '一'}}</p>
				</div>
				<div class="list-content">
					<p>价值描述</p>
					<p>{{a.valueDescription || '一'}}</p>
				</div>
				<div class="list-content">
					<p>业务实现逻辑</p>
					<p>{{a.businessImplDescription || '一'}}</p>
				</div>
				<div class="list-content">
					<p>优化或废弃说明</p>
					<p>{{a.versionDescription || '一'}}</p>
				</div>
			</li>
		{{# }); }}
	</ul>
</script>

<!--关联业务系统模板-->
<script id="contentBusinessSystemTpl" type="text/template">
	{{# layui.each(d, function(index, a){ }}
	<div>
		<img th:src="@{/img/Icon-xitong.png}"/><span>{{a.businessSystemName}}</span>
		<a class="pull-right" style = "cursor: pointer;" onclick="businessSystemDetail({{a.id}})">查看详情</a>
	</div>
	<div style="margin-top: 15px;color: rgba(0,0,0,0.85);">{{a.businessSystemDescription||''}}</div>
	{{# }); }}
</script>

<!--问题备注模板-->
<script id="contentQuestionTpl" type="text/template">
	{{# if(d.questionCount== 0){ }}
		<div class="empty">
			<p><img th:src="@{/img/empty.png}"/></p>
			<p>暂无问题备注</p>
			<p><button type="button" class="btn btn-primary add-question">提交问题</button></p>
		</div>
	{{# } else {}}
		<div class="questions">
			<p class="pull-left">当前共{{d.questionCount}}个问题</p>
			{{# if(d.owner) { }}
			<a class="pull-right add-question" style = "cursor: pointer;"><img th:src="@{/img/Icon-add.png}" class="icon" style="padding-right: 4px;margin-top: -3px;" />提问题</a>
			{{# } }}
		</div>
		<ul class="list-group ques-list">
			{{# layui.each(d.list, function(index, a){ }}
				<li class="list-group-item">
					<div>
						<div class="pull-left">
							<span><img class="head-img list-head-img" th:src="@{/img/login-background.jpg}"/>· {{a.createBy || '一'}} · {{a.createTime || '一'}}<span>
						</div>
						{{# if(d.owner) { }}
						<div class="pull-right">
							<icon class="icon del delete-question" data-id="{{a.id}}" style = "cursor: pointer;"></icon>
						</div>
						{{# } }}
					</div>
					<p>{{a.title || '一'}}</p>
					<p>{{a.description || '一'}}</p>
					<ul class="list-group-horizontal">
						{{# layui.each(a.fileInfList, function(indexB, b){ }}
						<li class="list-group-item" style="box-shadow:none"><img class = "partPage" src="{{b.filePath}}" th:onerror="this.src='/img/default-img.png'"/><p style="text-align: center">{{b.fileName}}</p></li>
						{{# }); }}
					</ul>
				</li>
			{{# }); }}
		</ul>

	{{#} }}
</script>

<script th:inline="javascript">
    // 接口uri
    const prefix = ctx + "usage/usage";
    $(function () {
		// 接口详情默认加载
		relationBusinessList();
	});

    $("body").on('click','.del',function(){
        $(this).parents(".list-group-item").remove();
    }).on('click', ".partPage", function(e) {
    	var url = $(this).attr("src");
        var json = {
            "title": "预览",
            "start": 0,
            "data": [{
                "src": url,
            }]
        };
        layer.photos({
            photos: json,
            closeBtn: 0, //右上角按钮，可通过配置1和2来展示，如果不显示，则closeBtn: 0
            anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
        });
	}).on('click', ".add-question", function () {
		var title = "提问题";
		var interfaceId = $("input[name='id']").val();
		var url = prefix + "/add_question/" + interfaceId + "/1";
		var width = 800;
		var height = $(window).height() - 50;
		$.modal.open(title, url, width, height);
	}).on('click', ".table-detail", function () {
	    var tableId = $(this).attr("tableId");
		$.operate.addTab2("表详情", prefix + "/table_detail/" + tableId);
    }).on('click','.virtualUsage .panel-heading',function(){
        var idName = $(this).attr("href");
        $(idName).html().length ==0 && paramList(idName, $(this).data("id"), 3);
    }).on('click','.delete-question',function(){
        var id = $(this).attr("data-id");
		var config = {
			url: ctx + "questionInfo/questionInfo/remove?ids=" + id,
			type: "POST",
			dataType: "json",
			data: null,
			beforeSend: function () {
				$.modal.loading("正在处理中，请稍后...");
			},
			success: function(result) {
				$.modal.closeLoading();
				if (result.code == web_status.SUCCESS) {
					$.modal.msgSuccess("删除成功");
					relationQuestionList();
				} else if (result.code == web_status.WARNING) {
					$.modal.alertWarning(result.msg)
				} else {
					$.modal.alertError(result.msg);
				}
			}
		};
		$.ajax(config);
    });

    /**标签切换事件*/
    $(".contentTab a").click(function (e) {
        var action = $(this).data("action");
        if(action) {
			window[action]();
		}
    });

	/**
	 * 业务需求
	 */
	function relationBusinessList() {
		var params = {};
		params.usageId = $("input[name='id']").val();
		var data={};
		var resultJson;
		var config = {
			url: prefix + "/businessList",
			type: "POST",
			dataType: "json",
			async: false,
			data: params,
			success: function (result) {
				if (result && result.code == 0) {
					resultJson = result.data;
				}
			}
		};
		$.ajax(config);
		data.businessList=resultJson;
		var contentBusinessTplHtml = $("#contentBusinessTpl").html();
		laytpl(contentBusinessTplHtml).render(data, function (html) {
			$("#content-business").empty();
			$("#content-business").append(html);
		});
    }

	/**
	 * bff
	 */
	function relationBff() {
		var params = {};
		params.usageId = $("input[name='id']").val();
		var resultJson;
		var config = {
			url: prefix + "/bffInfo",
			type: "POST",
			dataType: "json",
			async: false,
			data: params,
			success: function (result) {
				if (result && result.code == 0) {
					resultJson = result.data;
				}
			}
		};
		$.ajax(config);
		if (resultJson) {
			var contentBffTplHtml = $("#contentBffTpl").html();
			laytpl(contentBffTplHtml).render(resultJson, function (html) {
				$("#content-bff").empty();
				$("#content-bff").append(html);
			});
		} else {
			$("#content-bff").empty();
		}

	}

    /**
     * 关联页面函数
     */
    function relationPageList() {
        var params = {};
        params.usageId = $("input[name='id']").val();
        var resultJson;
        var config = {
            url: prefix + "/pageList",
            type: "POST",
            dataType: "json",
            async: false,
            data: params,
            success: function (result) {
                if (result && result.code == 0) {
                    resultJson = result.data;
                }
            }
        };
        $.ajax(config);

        var contentPageTplHtml = $("#contentPageTpl").html();
        laytpl(contentPageTplHtml).render(resultJson, function (html) {
            $("#content-page").empty();
            $("#content-page").append(html);
        });
    };

    /**
     * 关联业务系统函数
     */
    function relationBusinessSystemList() {
        var params = {};
        params.usageId = $("input[name='id']").val();
        var resultJson;
        var config = {
            url: prefix + "/businessSystemList",
            type: "POST",
            dataType: "json",
            async: false,
            data: params,
            success: function (result) {
                if (result && result.code == 0) {
                    resultJson = result.data;
                }
            }
        };
        $.ajax(config);
        if(!resultJson) {
            return false;
        }
        var contentBusinessSystemTplHtml = $("#contentBusinessSystemTpl").html();
        laytpl(contentBusinessSystemTplHtml).render(resultJson, function (html) {
            $("#content-service").empty();
            $("#content-service").append(html);
        });
    };

    function businessDetail(id) {
		$.operate.addTab2("业务需求详情", ctx + "business/businessInfo/detail/" + id);
	}

	function pageDetail(id) {
		$.operate.addTab2("页面详情", ctx + "page/page/detail/" + id);
	}

	function businessSystemDetail(id) {
		$.operate.addTab2("业务系统详情", ctx + "businessSystem/businessSystem/detail/" + id);
	}
	function bffDetail(id) {
		$.operate.addTab2("接口详情", ctx + "interface/interface/bffDetail/" + id);
	}
</script>
</html>
